<template>
  <div id="nav">
    <div class="navigation">
      <div class="rounds">
        <div class="round" style="background-color: red"></div>
        <div class="round" style="background-color: yellowgreen"></div>
        <div class="round" style="background-color: green"></div>
      </div>

      <div class="user_detail">
        <div class="user">
          <div class="user_img">
            <!-- 使用 el-avatar 组件来显示头像 -->
            <el-avatar :src="imageSrc" :size="50"></el-avatar>
          </div>
          <div class="user_name">{{ username }}</div>
        </div>
      </div>

      <div class="menu">
        <ul style="padding-left: 0%; margin: auto">
          <li class="msg">
            <router-link to="/index">
              <!-- <div class="unread" v-show="unread != 0">{{ unread }}</div> -->
              <div><i class="el-icon-chat-dot-square"></i></div>
              <span>消息</span>
            </router-link>
          </li>
          <li>
            <router-link to="/contacts">
              <div>
                <i class="el-icon-user"></i>
              </div>
              <span>联系人</span>
            </router-link>
          </li>
          <li>
            <router-link to="#3">
              <div>
                <i class="iconfont icon-shuyi_qunliao"></i>
              </div>
              <span>群聊</span>
            </router-link>
          </li>
          <li>
            <router-link to="#4">
              <div>
                <i class="el-icon-setting"></i>
              </div>
              <span>设置</span>
            </router-link>
          </li>
          <li class="bottom">
            <router-link to="#5">
              <div>
                <i class="el-icon-more"></i>
              </div>
              <span>更多</span>
            </router-link>
          </li>
          <li @click="logout">
            <router-link to="#6">
              <div>
                <i class="iconfont icon-tuichu"></i>
              </div>
              <span>退出</span>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
  
  <script>
export default {
  data() {
    return {
      imageSrc:"",
      username: "",  
      unread: 0,
    };
  },
  methods: {
    getInfo() {
      this.$http.get("/api/sysUser/detail").then((res) => {
        if (res.data.data != null) {
          this.username = res.data.data.username;
          this.imageSrc = res.data.data.avatar;
          this.$emit("handlerUser", res.data.data);
        }
      });
    },
    //退出登录
    logout() {
      this.$confirm("确定退出登录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //清除token 后端暂时没有提供退出登录接口
          localStorage.removeItem("token");
          this.$router.push("/login");
        })
        .catch(() => {});
    },
    getUnreadCount() {
      this.unread = this.$store.state.unread
    }
  },
  mounted() {
    this.getInfo();
    this.getUnreadCount();
  },
};
</script>
  
  <style lang="less" scoped>
#nav {
  .navigation {
    width: 80px;
    height: 700px;
    background-color: #f5f5f5;
    .rounds {
      height: 10px;
      margin: 2px 2px;
      .round {
        float: left;
        width: 10px;
        height: 10px;
        margin-right: 4px;
        border-radius: 50%;
      }
    }

    .menu {
      display: flex;
      height: 300px;
      margin-top: 20px;
      ul {
        list-style: none;
        .msg {
          position: relative;
          .unread {
            position: absolute;
          width: 20px;
          height: 20px;
          background-color: #ec4c4c;
          color: #ffffff;
          border-radius: 50%;
          text-align: center;
          line-height: 20px;
          left: 34px;
          top: -8px;
          }
        }
        li {
          height: 60px;
          text-align: center !important;
          color: #a6a0a0;
          margin-bottom: 5px;
          cursor: default;
          a {
            color: #a6a0a0;
          }
          a.router-link-active {
            color: #409eff;
          }
          a:hover {
            color: #409eff;
          }
          div {
            width: 50px;
          }
          i {
            font-size: 20px;
          }
          span {
            font-size: 16px;
          }
        }
        .bottom {
          margin-top: 185px;
        }
      }
    }
    .user_detail {
      width: 80px;
      height: 80px;
      margin-top: 30px;
      .user {
        width: 80px;
        height: 80px;
        .user_img {
          width: 50px;
          height: 50px;
          margin: 0 auto;
          border-radius: 50%;
        }
        .user_name {
          width: 80px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          font-style: italic;
          font-size: 11px;
        }
      }
    }

    .meun {
      display: flex;
      height: 300px;
      ul {
        list-style: none;
        li {
          height: 80px;
          text-align: center !important;
          div {
            width: 50px;
            height: 50px;
          }
          span {
            font-size: 14px;
          }
        }
      }
    }
  }
}

</style>
  